/*
*  Copyright 2019-2023 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.poemmanager.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import me.zhengjie.poemmanager.domain.ObjectLike;
import me.zhengjie.poemmanager.domain.vo.ObjectLikeQueryCriteria;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author hwl
* @date 2024-12-11
**/
@Mapper
public interface ObjectLikeMapper extends BaseMapper<ObjectLike> {

    IPage<ObjectLike> findAll(@Param("criteria") ObjectLikeQueryCriteria criteria, Page<Object> page);

    List<ObjectLike> findAll(@Param("criteria") ObjectLikeQueryCriteria criteria);

    @Select("select * from object_like where user_name=#{userName} and object_type=#{objectType} and object_id=#{objectId}")
    ObjectLike isLike(ObjectLike like);
    @Select("select count(*) from object_like where object_type=#{i} and object_id=#{id} ")
    Integer getLikeCount(Integer id, int i);

    @Update("update comment SET like_count = like_count + 1 WHERE comment_id = #{objectId}")
    void addCommentLikeCount(Integer objectId);
    @Update("update comment SET like_count = like_count - 1 WHERE comment_id = #{objectId}")
    void subCommentLikeCount(Integer objectId);

    @Update("update daily_poem_discussion SET like_count = like_count + 1 WHERE discussion_id = #{objectId}")
    void addDiscussionLikeCount(Integer objectId);
    @Update("update daily_poem_discussion SET like_count = like_count - 1 WHERE discussion_id = #{objectId}")
    void subDiscussionLikeCount(Integer objectId);

    // 插入方法组
    @Insert("INSERT INTO post_comment_like (user_name, object_id) VALUES (#{userName}, #{objectId})")
    @Options(useGeneratedKeys = true, keyProperty = "likeId")
    int createPostCommentLike(ObjectLike like);

    @Insert("INSERT INTO recitation_comment_like (user_name, object_id) VALUES (#{userName}, #{objectId})")
    @Options(useGeneratedKeys = true, keyProperty = "likeId")
    int createRecitationCommentLike(ObjectLike like);

    @Insert("INSERT INTO poem_user_comment_like (user_name, object_id) VALUES (#{userName}, #{objectId})")
    @Options(useGeneratedKeys = true, keyProperty = "likeId")
    int createPoemUserCommentLike(ObjectLike like);

    @Insert("INSERT INTO poem_poet_comment_like (user_name, object_id) VALUES (#{userName}, #{objectId})")
    @Options(useGeneratedKeys = true, keyProperty = "likeId")
    int createPoemPoetCommentLike(ObjectLike like);

    // 删除方法组
    @Delete("DELETE FROM post_comment_like WHERE like_id = #{likeId}")
    int deletePostCommentLike(@Param("likeId") Integer likeId);

    @Delete("DELETE FROM recitation_comment_like WHERE like_id = #{likeId}")
    int deleteRecitationCommentLike(@Param("likeId") Integer likeId);

    @Delete("DELETE FROM poem_user_comment_like WHERE like_id = #{likeId}")
    int deletePoemUserCommentLike(@Param("likeId") Integer likeId);

    @Delete("DELETE FROM poem_poet_comment_like WHERE like_id = #{likeId}")
    int deletePoemPoetCommentLike(@Param("likeId") Integer likeId);

    @Update("UPDATE post_comment SET like_count = like_count + 1 WHERE comment_id = #{objectId}")
    int addPostCommentLikeCount(@Param("objectId") Integer objectId);
    @Update("UPDATE poem_user_comment SET like_count = like_count + 1 WHERE comment_id = #{objectId}")
    int addPoemUserCommentLikeCount(@Param("objectId") Integer objectId);
    @Update("UPDATE poem_poet_comment SET like_count = like_count + 1 WHERE comment_id = #{objectId}")
    int addPoemPoetCommentLikeCount(@Param("objectId") Integer objectId);
    @Update("UPDATE recitation_comment SET like_count = like_count + 1 WHERE comment_id = #{objectId}")
    int addRecitationCommentLikeCount(@Param("objectId") Integer objectId);

    @Update("UPDATE post_comment SET like_count = like_count - 1 WHERE comment_id = #{objectId}")
    int subPostCommentLikeCount(@Param("objectId") Integer objectId);
    @Update("UPDATE poem_user_comment SET like_count = like_count - 1 WHERE comment_id = #{objectId}")
    int subPoemUserCommentLikeCount(@Param("objectId") Integer objectId);
    @Update("UPDATE poem_poet_comment SET like_count = like_count - 1 WHERE comment_id = #{objectId}")
    int subPoemPoetCommentLikeCount(@Param("objectId") Integer objectId);
    @Update("UPDATE recitation_comment SET like_count = like_count - 1 WHERE comment_id = #{objectId}")
    int subRecitationCommentLikeCount(@Param("objectId") Integer objectId);

    @Select("select * from post_comment_like where like_id = #{id}")
    ObjectLike selectByPostCommentLikeId(Integer id);
    @Select("select * from poem_user_comment_like where like_id = #{id}")
    ObjectLike selectByPoemUserCommentLikeId(Integer id);
    @Select("select * from poem_poet_comment_like where like_id = #{id}")
    ObjectLike selectByPoemPoetCommentLikeId(Integer id);
    @Select("select * from recitation_comment_like where like_id = #{id}")
    ObjectLike selectByRecitationCommentLikeId(Integer id);

    @Select("select * from post_comment_like where object_id = #{objectId} AND user_name = #{userName}")
    ObjectLike isPostCommentLike(Integer objectId, String userName);
    @Select("select * from poem_user_comment_like where object_id = #{objectId} AND user_name = #{userName}")
    ObjectLike isPoemUserCommentLike(Integer objectId, String userName);
    @Select("select * from poem_poet_comment_like where object_id = #{objectId} AND user_name = #{userName}")
    ObjectLike isPoemPoetCommentLike(Integer objectId, String userName);
    @Select("select * from recitation_comment_like where object_id = #{objectId} AND user_name = #{userName}")
    ObjectLike isRecitationCommentLike(Integer objectId, String userName);
}